﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class FinanceCenter_EarningList : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            DateTime dtime = DateTime.Now;
            tbStartTime.Value = DateTime.Parse(dtime.Year.ToString() + "-" + dtime.Month + "-01 00:00:00").ToString();
            tbEndTime.Value = dtime.ToString();

            BindData();

            //Log log = new Log();
            //log.UserID = _User.ID;
            //log.Operate = _User.RealityName + "查看收入明细记录";
            //log.UserIp = _User.LoginIP;
            //log.EditLog();
        }
    }

    #region Web 窗体设计器生成的代码

    override protected void OnInit(EventArgs e)
    {
        isRequestLogin = true;
        RequestCompetences = Competences.BuildCompetencesList(Competences.Finance);
        RequestLoginPage = "FinanceCenter/EarningList.aspx";

        base.OnInit(e);
    }

    #endregion

    private void BindData()
    {
        DateTime StartTime = ShoveEL._Convert.StrToDateTime(tbStartTime.Value.ToString(), DateTime.Now.ToShortDateString());
        DateTime EndTime = ShoveEL._Convert.StrToDateTime(tbEndTime.Value.ToString(), DateTime.Now.ToShortDateString());

        int Result = 0;
        string Return = "";

        DataSet ds = DAL.Procedures.P_InComingOrOutComing.Open(StartTime, EndTime, 1, ref Result, ref Return);

        if (ds == null)
        {
            ShoveEL._Web.JavaScript.Alert(this.Page, "数据库连接失败。");

            return;
        }

        g.DataSource = ds.Tables[0].DefaultView;
        g.DataBind();

        gPager.Visible = (ds.Tables[0].Rows.Count > 0);

        if (ds.Tables[1].Rows.Count > 0)
        {
            string strMoney = ds.Tables[1].Rows[0]["SumMoney"].ToString();
            lbUserCount.Text = ds.Tables[1].Rows[0]["SumID"].ToString();

            lbBuyCount.Text = (ShoveEL._Convert.StrToDouble(strMoney, 0) == 0) ? "0.00" : ShoveEL._Convert.StrToDouble(strMoney, 0).ToString("N");            
        }
    }

    protected void ibSelect_Click(object sender, ImageClickEventArgs e)
    {
        gPager.PageIndex = 0;

        BindData();
        //BindStatisticData();
        //Log log = new Log();
        //log.UserID = _User.ID;
        //log.Operate = _User.RealityName + "查看收入明细记录";
        //log.UserIp = _User.LoginIP;
        //log.EditLog();
    }

    protected void ibPrint_Click(object sender, ImageClickEventArgs e)
    {
        //Log log = new Log();
        //log.UserID = _User.ID;
        //log.Operate = _User.RealityName + "打印收入明细记录";
        //log.UserIp = _User.LoginIP;
        //log.EditLog();
        this.Response.Write("<script language='javascript'>window.open('EarningListForPrint.aspx?StartTime=" + tbStartTime.Value.ToString() + "&EndTime=" + tbEndTime.Value.ToString() + "');</script>");
    }

    protected void g_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.EditItem)
        {
            for (int i = 4; i <= 4; i++)
            {
                double money = ShoveEL._Convert.StrToDouble(e.Item.Cells[i].Text, 0);
                e.Item.Cells[i].Text = (money == 0) ? "" : money.ToString("N");
            }

            for (int i = 1; i <= ShoveEL._Convert.StrToInt(e.Item.Cells[7].Text,1);i++ )
            {
                e.Item.Cells[3].Text +="<img src='../Images/gold.gif' border='0'>";
            }
            

            string sequenceNumber = e.Item.Cells[0].Text.ToString();
            if (ShoveEL._Convert.StrToInt(sequenceNumber, 0) >= 10)
            {
                e.Item.Cells[0].Text = "0" + sequenceNumber;
            }
            else
            {
                e.Item.Cells[0].Text = "00" + sequenceNumber;
            }
        }
    }

    protected void gPager_PageWillChange(object Sender, Shove.Web.UI.PageChangeEventArgs e)
    {
        BindData();
    }

    protected void gPager_SortBefore(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
    {
        BindData();
    }
}

